// 144. 二叉树的前序遍历
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
 var preorderTraversal = function(root) {
    let res=[];
    const def=function(root){
        if(root==null) return;
        res.push(root.val);
        def(root.left);
        def(root.right);
    }
    def(root);
    return res;
};

// 145. 二叉树的后序遍历
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
 var postorderTraversal = function(root) {
    let res=[];
    const def=function(root){
        if(root==null) return;
        def(root.left);
        def(root.right);
        res.push(root.val);
    }
    def(root);
    return res;
};

// 94. 二叉树的中序遍历
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
 var inorderTraversal = function(root) {
    let res=[];
    const def=function(root){
        if(root==null) return;
        def(root.left);
        res.push(root.val);
        def(root.right);
    }
    def(root);
    return res;
};